#include<Wire.h>
#include<Servo.h>
/*
1 2 3
4 5 6
7 8 9
*/
#define SLAVE_ADDR 0x04
#define left '4'
#define right '6'
#define up '2'
#define down '8'

Servo servo_h;
Servo servo_v;

static int pos_h=90;
static int pos_v=90;

void setup()
{
	Serial.begin(9600);           // start serial for output

	servo_h.attach(9);			//horizen at 9
	servo_v.attach(10);			//vertical at 10
	servo_h.write(pos_h);
	servo_v.write(pos_v);
}

void loop()
{
        while(Serial.available()) receiveEvent();
	delay(100);
}

void receiveEvent()
{
	int x = Serial.read();    // receive byte as an integer
	Serial.println(x);         // print the integer
	if(x==up && pos_v<=175) pos_v --;
	if(x==down && pos_v>=5) pos_v ++;
	if(x==left && pos_h>=5) pos_h ++;
	if(x==right && pos_h<=175) pos_h --;
	servo_h.write(pos_h);
	servo_v.write(pos_v);
}


